package main

//curl -si -X POST -d "some data to send" http://localhost:8000/

import (
	"bytes"
	"encoding/json"
	"fmt"
	"io/ioutil"
	"net/http"
	"runtime"
	"strconv"
)

type ClientReq struct {
	Input  string `json:"input"`
	Output string `json:"output"`
}

func douyu_client() {

	var url string
	var input string
	var output string

	if runtime.GOOS == "linux" {
		url = "http://74.120.174.240:8090/rtmp"
		input = "/root/code/mp4/music/h2f1LLjhb0U.mp4"
		output = "rtmp://send3.douyu.com/live/1480416rV0oNxGIV?wsSecret=2e802380686a11a66d82a214c2d92966&wsTime=5e6f6d45&wsSeek=off&wm=0&tw=0&roirecognition=0"

	} else {
		url = "http://74.120.174.240:8090/rtmp"

		//input = "/root/data/yoga/1.mkv"
		input = "/root/data/keep/playlist.txt"
		//斗鱼
		output = strconv.Quote("rtmp://sendtc3a.douyu.com/live/1480416r74FoaiUK?wsSecret=6cb02ccd730aff4836837fbec5981055&wsTime=6018c891&wsSeek=off&wm=0&tw=0&roirecognition=0&record=flv&origin=tct")
	}
	//bug2 http://www.voidcn.com/article/p-rirbytik-bqc.html

	reqData := &ClientReq{
		Input:  input,
		Output: output,
	}
	bf := bytes.NewBuffer([]byte{})
	jsonEncoder := json.NewEncoder(bf)
	jsonEncoder.SetEscapeHTML(false)
	jsonEncoder.Encode(reqData)

	fmt.Println("buf=", bf)

	fmt.Println("url=", url)
	fmt.Println("output=", output)
	req, err := http.NewRequest("POST", url, bf)
	//bug1 https://www.jianshu.com/p/2f7bdfe6f73d

	req.Header.Set("Content-Type", "application/json")

	client := &http.Client{}
	resp, err := client.Do(req)
	if err != nil {
		panic(err)
	}
	defer resp.Body.Close()

	fmt.Println("response Status:", resp.Status)
	fmt.Println("response Headers:", resp.Header)
	body, _ := ioutil.ReadAll(resp.Body)
	fmt.Println("response Body:", string(body))
}
